﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jemgine.Engine.Scripts
{
    [Category("System"), Node]
   public class ToggleMotor: Data.ScriptNode
    {
       public ToggleMotor()
       {
           AddInput("Fire", null);
           AddReference("Joint", null);
           AddOutput("Relay", null);
       }

       public override void FireTerminal(int InputID, Data.ScriptPayload Payload)
       {
           //Can't operate on SenderRef, since dynamics can't be the SenderRef.
           Data.ReferenceTarget Ref = ReferenceTerminals[0].GetTarget(Payload);
           if (Ref is Data.Dynamic)
           {
               Data.Dynamic Dynamic = Ref as Data.Dynamic;
               Box2D.XNA.RevoluteJoint Joint = Dynamic.Joint as Box2D.XNA.RevoluteJoint;
               if (Joint != null) Joint.EnableMotor(!Joint.IsMotorEnabled());
           }

           OutputTerminals[0].Fire(Payload);
       }

      
    }
}
